//引入请求的工具
import ajax from "@/utils/request.js";

//封装登录的接口
const login = obj => {
  return ajax({
    url: "/app/v1_0/authorizations",
    method: "POST",
    data: {
      mobile: obj.mobile,
      code: obj.code
    }
  });
};

//关注用户的接口
const followUser = userId => {
  return ajax({
    url: "/app/v1_0/user/followings",
    method: "POST",
    data: {
      target: userId
    }
  });
};

//取消关注用户
const unFollowUser = userId => {
  return ajax({
    url: `/app/v1_0/user/followings/${userId}`,
    method: "DELETE"
  });
};

//获取用户自己的信息
const getInfo = () => {
  return ajax({
    method: "GET",
    url: "/app/v1_0/user"
  });
};

//用户个人资料
const getUserSelf = () => {
  return ajax({
    method: "GET",
    url: "/app/v1_0/user/profile"
  });
};

//编辑用户个人资料
const updateUserInfo = formData => {
  return ajax({
    method: "PATCH",
    url: "/app/v1_0/user/profile",
    data: formData
  });
};

/**
 * 修改用户的头像信息
 * @param {*} formData formData格式的对象
 */
const updatePhoto = formData => {
  return ajax({
    method: "PATCH",
    url: "/app/v1_0/user/photo",
    data: formData
  });
};

//导出接口
export {
  login,
  followUser,
  unFollowUser,
  getInfo,
  getUserSelf,
  updateUserInfo,
  updatePhoto
};
